<div class="layuimini-main">
    <div class="layui-form layuimini-form" lay-filter="infoForm">
        <div class="layui-form-item">
            <label class="layui-form-label ">账号</label>
            <div class="layui-input-block">
                <input type="text" name="account" disabled value="admin" class="layui-input">
                <tip>帐号不可修改</tip>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value=""
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="1" title="男"/>
                <input type="radio" name="gender" value="0" title="女"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">年龄</label>
            <div class="layui-input-block">
                <input type="number" name="age" lay-verify="required|age" lay-reqtext="年龄不能为空" placeholder="请输入年龄" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">手机</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required|phone" lay-reqtext="手机不能为空" placeholder="请输入手机号码" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" lay-verify="required|email" lay-reqtext="邮箱不能为空" placeholder="请输入邮箱" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'miniPage'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniPage = layui.miniPage;

        axios({
            url: 'family/userInfo',
            method: 'get'
        }).then(response => {
            console.log(response)
            let data = response.data;
            form.val("infoForm", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                "account": data.account
                ,"name": data.name
                ,"gender": data.gender
                ,"age": data.age
                ,"phone": data.phone
                ,"email": data.email
                ,"remark": data.remark
            });

        }).catch(error => {
            layer.msg(error);
        })

        form.verify({
            age: function (value, item) {
                if (value <= 0 || value > 150){
                    return "年龄数值不合理";
                }
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            axios({
                url: 'family/updateMember',
                method: 'post',
                data: data.field
            }).then(response => {
                console.log(response);
                layer.msg(response.msg, function () {
                    miniPage.hashHome();
                })

            }).catch(error => {
                layer.msg(error)
            })
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //     layer.close(index);
            //     miniPage.hashHome();
            // });
            return false;
        });





    });
</script>